/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nsip.model;

/**
 *
 * @author nico.rehwaldt
 */
public class DataRecord {
    
    protected int id = Integer.MIN_VALUE;
    protected int productID = -1;

    protected ItemType type;
    protected ItemStatus status;
    
    protected int dueDate = -1;
    protected int quantity = -1;
    protected int penalty = -1;
    protected int pricePerUnit = -1;
    
    protected String peerAddress = null;

    protected DataRecord() { }
    
    public DataRecord(ItemType type, ItemStatus status) {
        this.type = type;
        this.status = status;
        this.id = -1;
    }

    public DataRecord(int id, int productID, ItemType type, ItemStatus status, 
                      int dueDate, int quantity, int penalty, int pricePerUnit,
                      String peerAddress) {

        this(type, status);
        
        this.id = id;
        this.productID = productID;
        this.dueDate = dueDate;
        this.quantity = quantity;
        this.penalty = penalty;
        this.pricePerUnit = pricePerUnit;
        this.peerAddress = peerAddress;
    }

    void update(Item item) {
        
        if (id != Integer.MIN_VALUE) { item.id = id; }
        if (productID != -1) { item.productID = productID; }

        if (type != null) { item.type = type; }
        if (status != null) { item.status = status; }
        if (dueDate != -1) { item.dueDate = dueDate; }
        if (quantity != -1) { item.quantity = quantity; }
        if (penalty != -1) { item.penalty = penalty; }
        if (pricePerUnit != -1) { item.pricePerUnit = pricePerUnit; }
        if (peerAddress != null) { item.peerAddress = peerAddress; }
    }

    public static class CustomerRFQ extends DataRecord {
        
        public CustomerRFQ(int id, int productID, int dueDate, int quantity,
                           int penalty, int pricePerUnit, String peerAddress) {

           super(id, productID, ItemType.RFQ, ItemStatus.OPEN, dueDate,
                 quantity, penalty, pricePerUnit, peerAddress);
       }
    }
    
    public static class CustomerOffer extends DataRecord {
        public CustomerOffer(int dueDate, int quantity, int pricePerUnit) {
            super(ItemType.OFFER, ItemStatus.OPEN);

            this.dueDate = dueDate;
            this.quantity = quantity;
            this.pricePerUnit = pricePerUnit;
        }
    }

    public static class CustomerOrder extends DataRecord {
        public CustomerOrder(int id) {
            super(ItemType.ORDER, ItemStatus.OPEN);
            this.id = id;
        }
    }

    public static class SupplierOffer extends DataRecord {

        public SupplierOffer(int id, int dueDate, int quantity, int pricePerUnit) {
            super(ItemType.OFFER, ItemStatus.OPEN);
            
            this.id = id;
            this.dueDate = dueDate;
            this.quantity = quantity;
            this.pricePerUnit = pricePerUnit;
        }
    }
    
    public static class SupplierRFQ extends DataRecord {

        public SupplierRFQ(String peerAddress, int productID, int quantity, int dueDate) {

            super(ItemType.RFQ, ItemStatus.OPEN);

            this.peerAddress = peerAddress;
            this.productID = productID;
            this.quantity = quantity;
            this.pricePerUnit = 0;
            this.penalty = 0;
            this.dueDate = dueDate;
        }
    }

    public static class SupplierOrder extends DataRecord {
        
        public SupplierOrder() {
            super(ItemType.ORDER, ItemStatus.OPEN);
        }
    }
}
